﻿using System.Windows;
using GalaSoft.MvvmLight.Threading;
using System;
using System.Windows.Threading;

namespace LPS
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            DispatcherHelper.Initialize();
           this.Startup += new StartupEventHandler(App_Startup);
           this.Exit += new ExitEventHandler(App_Exit);
           this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
        }

        void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            if (!System.Diagnostics.Debugger.IsAttached)
            {

                // NOTE: This will allow the application to continue running after an exception has been thrown
                // but not handled. 
                // For production applications this error handling should be replaced with something that will 
                // report the error to the website and stop the application.
                
                ReportErrorToDOM(e);
            }
        }

        void App_Exit(object sender, ExitEventArgs e)
        {
            
        }

        static void App_Startup(object sender, StartupEventArgs e)
        {
           
            
        }
       
       
        private void ReportErrorToDOM(DispatcherUnhandledExceptionEventArgs e)
        {
            try
            {
                string errorMsg = e.Exception.Message;
                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

                MessageBox.Show("throw new Error(\"Unhandled Error in  Application " + errorMsg + "\");");
            }
            catch (Exception)
            {
            }
        }
    }
}
